/*
 *  Copyright 1999-2021 Seata.io Group.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.diy.sigmund.diyorder.controller;

import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.spring.anno.IgnoreTokenVerification;
import com.diy.sigmund.diyorder.entity.po.OdSeckillOrder;
import com.diy.sigmund.diyorder.service.SeataOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author IT云清
 */
@RestController
@RequestMapping(value = "")
public class SeataOrderController {

    @Autowired
    private SeataOrderService seataOrderServiceImpl;

    /**
     * 创建订单
     *
     * @param order
     * @return
     */
    @IgnoreTokenVerification
    @GetMapping("/order/seataOrder/create")
    public ResultMsg create(OdSeckillOrder order) {
        return seataOrderServiceImpl.create(order);
    }

    /**
     * 修改订单状态
     */
    @IgnoreTokenVerification
    @RequestMapping("/order/seataOrder/update")
    public ResultMsg update(@RequestParam("orderId") String orderId, @RequestParam("orderStatus") String orderStatus) {
        return seataOrderServiceImpl.update(orderId, orderStatus);
    }

    @IgnoreTokenVerification
    @RequestMapping("/order/seataOrder/decreaseInventory")
    public ResultMsg decreaseInventory(@RequestParam String commodityId, @RequestParam Integer transactionQuantity) {
        return seataOrderServiceImpl.decreaseInventory(commodityId,transactionQuantity);
    }
}
